﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using System.ComponentModel;
using System.Web;
using Skynet.BusinessLogic.BusinessComponents;

namespace Skynet.WebAdministracion.Views.ExamResultMgm
{
    [System.ComponentModel.DataObject]
    public class ExamResultMgmPresenter :  Infrastructure.Web.Views.Master.MasterPresenter<IExamResultMgmView>
    {
        [Dependency]
        public WebFoundation.Services.Session.ISessionService SessionService { get; set; }


        [Dependency]
        public WebFoundation.Services.Navigation.INavigationService NavigationService { get; set; }


        [Dependency]
        public BusinessLogic.BusinessComponents.IBCExamQueries BCExamQueries { get; set; }

        [Dependency]
        public BusinessLogic.BusinessComponents.IBCCustomers BCCustomers { get; set; }


        [Dependency]
        public IBCCustomersQueries BCCustomersQueries { get; set; }


        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public IEnumerable<object> GetResultsExams()
        {
            var userName = HttpContext.Current.User.Identity.Name;
            var customer = this.BCCustomersQueries.FindCustomers(option: BusinessLogic.BusinessComponents.CustomerFindOptions.GetByUserName, UserName: userName).SingleOrDefault();
            var exams = this.BCExamQueries.SearchExamByCustomer(options: ExamByCustomerSearchOptions.RuntimeCompleteByCustomerId, CustomerId: customer.Id);
            var query = (from c in exams select new { Id = c.Id, Category = c.Exam.ExamCategory.Title, Title = c.Exam.Title, Duration = c.Duration, Score = c.Score }).ToList();
            return query;
        }


    }
}
